﻿using B.S.BasicData.Api.Read.Application.Command.Role;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.Role
{
    public class GetRoleHandler : IRequestHandler<GetRoleCommand, ApiResult<List<RoleModel>>>
    {
        private readonly IBaseRepository<RoleModel> roleRope;

        public GetRoleHandler(IBaseRepository<RoleModel> roleRope)
        {
            this.roleRope = roleRope;
        }
        public Task<ApiResult<List<RoleModel>>> Handle(GetRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<RoleModel>> res = new ApiResult<List<RoleModel>>();
            var role = roleRope.GetAll().Where(x => x.IsDelete == false).ToList();
            res.Msg = "显示角色信息成功";
            res.Data = role.OrderByDescending(x => x.Id).ToList();
            res.Code = ApiEnum.Success;
            return Task.FromResult(res);
        }
    }
}
